// 封装request

const baseURL = 'https://api-hmugo-web.itheima.net/api/public/v1'

// 准备一个请求计算器
let requestCount = 0;

const request = ({url,...config})=>{
    return new Promise((resolve,reject) => {
        // 用户加载提示
        uni.showNavigationBarLoading()

        requestCount++;
        uni.request({
            ...config,
            url: baseURL + url, 
            success: (res) => {
                resolve(res)
            },
            fail:(res) => {
                reject(res)
            },
            complete:() => {
                requestCount--;
                uni.hideNavigationBarLoading()
            }
        });
    })
}

export default request